From: Aleksey Kladov Date: Wed, 7 Mar 2018 08:22:46 +0000 (+0300) Subject: Move doc to clap X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~47^2~64 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=84a89ebb25cf3b732af00f50c5285f03a31e21a2;p=cargo.git Move doc to clap --- diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 485dc9d62..ed84f0ed2 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -89,7 +89,7 @@ fn main() { }; let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() { - "build" | "bench" | "check" | "clean" => true, + "build" | "bench" | "check" | "clean" | "doc" => true, _ => false }); @@ -121,7 +121,7 @@ macro_rules! each_subcommand{ // $mac!(build); // $mac!(check); // $mac!(clean); - $mac!(doc); +// $mac!(doc); $mac!(fetch); $mac!(generate_lockfile); $mac!(git_checkout); diff --git a/src/bin/cli/bench.rs b/src/bin/cli/bench.rs index d52f45ec3..09afcca2b 100644 --- a/src/bin/cli/bench.rs +++ b/src/bin/cli/bench.rs @@ -14,7 +14,7 @@ pub fn cli() -> App { ).multiple(true).last(true) ) - .arg_target( + .arg_targets_all( "Benchmark only this package's library", "Benchmark only the specified binary", "Benchmark all binaries", diff --git a/src/bin/cli/build.rs b/src/bin/cli/build.rs index 645be8279..9316ca7a9 100644 --- a/src/bin/cli/build.rs +++ b/src/bin/cli/build.rs @@ -9,7 +9,7 @@ pub fn cli() -> App { "Exclude packages from the build", ) .arg_jobs() - .arg_target( + .arg_targets_all( "Build only this package's library", "Build only the specified binary", "Build all binaries", diff --git a/src/bin/cli/check.rs b/src/bin/cli/check.rs index db7277748..c482fb55c 100644 --- a/src/bin/cli/check.rs +++ b/src/bin/cli/check.rs @@ -9,7 +9,7 @@ pub fn cli() -> App { "Exclude packages from the check", ) .arg_jobs() - .arg_target( + .arg_targets_all( "Check only this package's library", "Check only the specified binary", "Check all binaries", diff --git a/src/bin/cli/doc.rs b/src/bin/cli/doc.rs new file mode 100644 index 000000000..7e158c2ed --- /dev/null +++ b/src/bin/cli/doc.rs @@ -0,0 +1,42 @@ +use super::utils::*; + +pub fn cli() -> App { + subcommand("doc") + .about("Build a package's documentation") + .arg( + opt("open", "Opens the docs in a browser after the operation") + ) + .arg_package( + "Package to document", + "Document all packages in the workspace", + "Exclude packages from the build", + ) + .arg( + opt("no-deps", "Don't build documentation for dependencies") + ) + .arg_jobs() + .arg_targets_lib_bin( + "Document only this package's library", + "Document only the specified binary", + "Document all binaries", + ) + .arg_release("Build artifacts in release mode, with optimizations") + .arg_features() + .arg_target_triple("Build for the target triple") + .arg_manifest_path() + .arg_message_format() + .arg_locked() + .after_help("\ +By default the documentation for the local package and all dependencies is +built. The output is all placed in `target/doc` in rustdoc's usual format. + +All packages in the workspace are documented if the `--all` flag is supplied. The +`--all` flag is automatically assumed for a virtual manifest. +Note that `--exclude` has to be specified in conjunction with the `--all` flag. + +If the --package argument is given, then SPEC is a package id specification +which indicates which package should be documented. If it is not given, then the +current package is documented. For more information on SPEC and its format, see +the `cargo help pkgid` command. +") +} diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index 7edf41ff5..9cf8e95b5 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -73,7 +73,7 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { let spec = Packages::from_flags( args.is_present("all"), &values(args, "exclude"), - &values(args, "package") + &values(args, "package"), )?; let release = mode == CompileMode::Bench || args.is_present("release"); @@ -150,7 +150,7 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { Some(profile) => { let err = format_err!("unknown profile: `{}`, only `test` is \ currently supported", profile); - return Err(CliError::new(err, 101)) + return Err(CliError::new(err, 101)); } }; let mode = CompileMode::Check { test }; @@ -170,6 +170,18 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { ops::clean(&ws, &opts)?; return Ok(()); } + ("doc", Some(args)) => { + config_from_args(config, args)?; + let ws = workspace_from_args(config, args)?; + let mode = ops::CompileMode::Doc { deps: !args.is_present("no-deps") }; + let compile_opts = compile_options_from_args(config, args, mode)?; + let doc_opts = ops::DocOptions { + open_result: args.is_present("open"), + compile_opts, + }; + ops::doc(&ws, &doc_opts)?; + return Ok(()); + } _ => return Ok(()) } } @@ -236,6 +248,7 @@ See 'cargo help ' for more information on a specific command. build::cli(), check::cli(), clean::cli(), + doc::cli(), ]) ; app @@ -245,6 +258,7 @@ mod bench; mod build; mod check; mod clean; +mod doc; mod utils { use clap::{self, SubCommand, AppSettings}; @@ -268,7 +282,7 @@ mod utils { ) } - fn arg_target( + fn arg_targets_all( self, lib: &'static str, bin: &'static str, @@ -281,9 +295,7 @@ mod utils { benchs: &'static str, all: &'static str, ) -> Self { - self._arg(opt("lib", lib)) - ._arg(opt("bin", bin).value_name("NAME").multiple(true)) - ._arg(opt("bins", bins)) + self.arg_targets_lib_bin(lib, bin, bins) ._arg(opt("example", examle).value_name("NAME").multiple(true)) ._arg(opt("examples", examles)) ._arg(opt("test", test).value_name("NAME").multiple(true)) @@ -293,6 +305,17 @@ mod utils { ._arg(opt("all-targets", all)) } + fn arg_targets_lib_bin( + self, + lib: &'static str, + bin: &'static str, + bins: &'static str, + ) -> Self { + self._arg(opt("lib", lib)) + ._arg(opt("bin", bin).value_name("NAME").multiple(true)) + ._arg(opt("bins", bins)) + } + fn arg_features(self) -> Self { self ._arg(